package com.colin.app.activity.splash;

import android.view.animation.Animation;

import com.colin.app.activity.main.MainActivity;
import com.colin.app.app.AppActivity;
import com.colin.app.app.BasePresenterImpl;
import com.colin.library.help.AndroidHelp;
import com.colin.library.help.LogHelp;

/**
 * Created by Colin on 2017/1/15.
 */

public class SplashPresenterImpl extends BasePresenterImpl implements SplashContract.SplashPresenter {

    private SplashContract.SplashView mSplashView;
    private SplashContract.SplashModel mSplashModel;

    public SplashPresenterImpl(AppActivity mAppActivity, SplashContract.SplashView mSplashView) {
        super(mAppActivity, mSplashView);
        this.mSplashView = mSplashView;
        this.mSplashModel = new SplashModelImpl();
    }

    /**
     * 权限检查
     * 版本检查（升级）
     * 动画开始下一页
     */
    @Override
    public void setData() {
        int versionCode = AndroidHelp.getInstance().getVersionCode(mAppActivity);
        LogHelp.e("versionCode=="+String.valueOf(versionCode));
        if (mSplashView.initPermissionList(mSplashModel.getPermissionList())) {
            next();
        }
    }
    @Override
    public void next() {
        startAnimation();
    }
    private void startAnimation() {
        Animation animation = mSplashModel.getAnimation();
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                mSplashView.startActivity(MainActivity.class, null, true);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        mSplashView.startAnimation(animation);
    }


}
